import serial

BAUDRATE = 9600

if __name__ == "__main__":
    port = serial.Serial("COM3", BAUDRATE)
    print "Abriu conexao"
    
    # Handshake
    #port.read() # precisa ler alguma coisa antes, talvez bug?
    port.write('A')
    print "Handshake completado"
    
    while(1):
        x = raw_input()
        if (x == 'X' or x == 'x') :
            port.write('X')
        elif (x == 'Z' or x == 'z') :
            break;
        else :
            port.write('a')
    
    port.close()